Skip to content

Commit

Permalink
Update scraper.py
Browse files Browse the repository at this point in the history
  • Loading branch information
BCG12345 committed Jan 13, 2024
1 parent f2316be commit dc4ea2a
Showing 1 changed file with 6 additions and 42 deletions.
48 changes: 6 additions & 42 deletions scraper.py
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
# This is a template for a Python scraper on morph.io (https://morph.io)
# including some code snippets below that you should find helpful

# import scraperwiki
# import lxml.html
import scraperwiki
import lxml.html
#
# # Read in a page
# html = scraperwiki.scrape("http://foo.com")
html = scraperwiki.scrape("http://foo.com")
#
# # Find something on the page using css selectors
# root = lxml.html.fromstring(html)
# root.cssselect("div[align='left']")
root = lxml.html.fromstring(html)
root.cssselect("div[align='left']")
#
# # Write out to the sqlite database using scraperwiki library
# scraperwiki.sqlite.save(unique_keys=['name'], data={"name": "susan", "occupation": "software developer"})
scraperwiki.sqlite.save(unique_keys=['name'], data={"name": "susan", "occupation": "software developer"})
#
# # An arbitrary query against the database
# scraperwiki.sql.select("* from data where 'name'='peter'")
Expand All @@ -22,39 +22,3 @@
# All that matters is that your final data is written to an SQLite database
# called "data.sqlite" in the current working directory which has at least a table
# called "data".






import requests

url = 'http://pu.edu.pk/home/results_show/2167'
payload = {
'result_title': 'Bachelor of Commerce Part-II, Annual Examination 2008',
'roll_no': '2',
'submitcontact': 'Submit'
}

# Add headers as observed in the DevTools
headers = {
'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/120.0.0.0 Safari/537.36',
'Referer':url,
'Host': 'pu.edu.pk',
'Origin': 'http://pu.edu.pk',
'Upgrade-Insecure-Requests': '1',
'Accept': 'text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.7',
'Accept-Encoding': 'gzip, deflate',
'Accept-Language': 'en-US,en;q=0.9',
'Cache-Control': 'max-age=0',
'Connection': 'keep-alive',
}

response = requests.post(url, data=payload, headers=headers)

if response.status_code == 200:
data = response.text
print(data)
else:
print(f"Failed to retrieve data. Status code: {response.status_code}")

0 comments on commit dc4ea2a

Please sign in to comment.