简体   繁体   中英

Injecting HTML into a page using Mechanize

I am writing a webscraping program to get my grades from a website. I used Mechanize to log into the page and navigate to the area I'm scraping. Unfortunately, the page uses Javascript to encrypt the page (possibly to stop me from scraping). I found the decryption script and ported to Python. It works and I used it to extract the encrypted string from the page and when I convert it, it becomes a table in HTML.

So, to get to my point, is there any way to inject the HTML back into the page and use mechanize to use the links on the table to get my grades?

Thanks for the help!

EDIT: I have beautiful soup also, if that is any help.

I ended up just using this:

response = br.open("www.linknotonpagethatiwanttogoto.com")
page = response.read()

I found out that you store the .open() of a link as a response, instead of using the .follow_link(). Also the browser uses the same cookies so the session cookies are preserved. So after parsing the html, I popped the links into the .open() and got the new page.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM