我已经创建了一个链接列表,链接到LinkedIn的页面。这些链接是使用LinkedInsRecruiter函数聚合的(在付费墙后面)。当我将链接粘贴到浏览器中并检查html代码时,它看起来很标准,而且我能够轻松地识别我正在搜索的元素(见下文)。你知道吗
但是,当我运行python代码并使用beautiful soup获取HTML时,返回的HTML与浏览器的inspect元素视图中的外观完全不同。HTML中没有普通的标签,而是充满了变量,基本上我以前没见过什么(没有做过大量的删减)。你知道吗
有没有可能让HTML看起来像我在我的浏览器上看到的东西,而不是这些疯狂的东西?这些链接是使用递归搜索函数编写的,所以我想我是在用搜索变量而不是实际结果拉html,但我真的不知道。你知道吗
这是我用来用html创建文件的代码。我希望最后一行提取我正在寻找的数据,假设我可以得到正确的html。你知道吗
#Used to create file
with open('departures.csv', mode='r') as csv_file:
csv_reader = csv.DictReader(csv_file)
for row in csv_reader:
browser.get(row['link'])
page = BeautifulSoup(browser.page_source, 'lxml')
html = page.prettify()
with open("output1.html", "w") as file:
file.write(unicode(html))
#Code I want to Run right now it just returns an empty list
position = page.find_all('span', class_= 'keyword')
我试图找到的HTML在我使用浏览器转到链接时显示:
<span class="keyword"> Account Manager</span>
Small Piece of Actual HTML returned: <code id="profile-data" style="display: none;">
<!--{"breadcrumbs":{"customSearchURL":"/recruiter/smartsearch? updateSearchHistory=false&decorateHits=true&decorateFacets=false&doFacetCounting=true&searchHistoryId=3392867616&resetFacets=false&searchCacheKey=f4b1a865-50e8-4f59-ba48-9dff595e63e5%2CoUbi&searchRequestId=4d25da0f-1f73-4722-8586-9652b3f98b97%2CQSZO&doResultCaching=false&forceResultFromCache=false&origin=PPSL&doProjectBasedCounting=false&count=25&start=700","linkContext":"Controller:smartSearch,Action:search,ID:3392867616","context":
LinkedIn使用大量JavaScript来生成您在浏览器中看到的页面。开发人员工具中的DOM元素检查器显示JS执行的当前结果,而不是浏览器下载的原始HTML页面。你知道吗
要在浏览器中查看实际的HTML页源,请使用“查看源”(Ctrl+U或Command+U)。它应该显示类似于Python的HTML。你知道吗
如果需要对最终生成的DOM输出执行一些刮取操作,则可能需要使用可以执行JavaScript(如Chrome controlled by Puppeteer)的headless browser。你知道吗
相关问题 更多 >
编程相关推荐